home *** CD-ROM | disk | FTP | other *** search
- .KF:Num.toc
- .R:E
- .W:96
- .H:...DML NUM UNIT Version 1.00...
- .H:...$$Day Mon D, YEAR$$ $$Z:MI A.M.$$ Page $$$...
- .H:
- .F:
- .F:... Copyright (c) 1989, by DML Software Inc. ...
- .X:8
-
-
- .K:NUMERIC ROUTINES - CHANGES HIGHLIGHTS (VERSION 1.00)
- NUMERIC ROUTINES - CHANGES HIGHLIGHTS (VERSION 1.00)
-
- 1/1/89 Initial Release
-
-
-
- .K:1) GENERAL NUMERIC FORMATTING AND CONVERSION
- 1) GENERAL NUMERIC FORMATTING AND CONVERSION
-
- NAME
- .K:B2S - Boolean to String Conversion.
- B2S - Boolean to String Conversion.
-
- SYNOPSIS
- FUNCTION B2S (Flag : BOOLEAN) : STRING;
-
- WRITELN (B2S (123 = 123));
-
- DESCRIPTION
- Returns a string of TRUE or FALSE depending on th value of the Boolean
- parameter.
-
- SEE ALSO
-
- DEPENDS ON
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:I2S - Integer to String Conversion
- I2S - Integer to String Conversion
- .K:W2S - Word to String Conversion
- I2S - Word to String Conversion
- .K:L2S - LongInt to String Conversion
- L2S - LongInt to String Conversion
-
- SYNOPSIS
- FUNCTION I2S (Num : INTEGER; Mask : STRING) : STRING;
- FUNCTION W2S (Num : WORD; Mask : STRING) : STRING;
- FUNCTION L2S (Num : LONGINT; Mask : STRING) : STRING;
-
- WRITELN ('The meaning of everything: ', I2S (42, '##'));
- WRITELN ('Bit fields in hex: ', W2S (AX, 'HHHH'));
- WRITELN ('Big number: ', L2S (-12345678, '-###,###,##@'));
-
- DESCRIPTION
- Returns a string of the number passed. The following characters can
- be used in the mask string. Remember that the case of the character
- is important and that 'H' <> 'h'.
-
- sp - The space character will be output in this position.
-
- # ###.## : 1234.56 = '1 234.56', 50.00 = ' 50 ', 0 = ' '
-
- # - Digit base 10, leading and trailing zero digits are blank.
-
- # ###.## : 1234.56 = '1 234.56', 50.00 = ' 50 ', 0 = ' '
-
- H - Digit base 16, leading and trailing zero digits are blank. (Int only)
-
- HHHH : 43981 = 'ABCD' , 50 = ' 32' , 0 = ' '
-
- B - NOT IMPLEMENTED (for binary)
-
- BBBB : 10 = '1010' , 2 = ' 10' , 0 - ' '
-
- @ - Digit, from position to decimal point, zero digits are '0'.
-
- # #@#.#@ : 1234.56 = '1 234.56', 50.00 = ' 50.00', 0 = ' 00.00'
-
- * - Digit, from position to decimal point, zero digits are '*'.
-
- # #*#.#* : 1234.56 = '1 234.56', 50.00 = ' 50***', 0 = ' **.**'
-
- $ - Space before number is a dollar sign. NOT a digit position.
- Can also follow the number.
-
- $####.## : 1234.56 = '$1234.56', 50.00 = ' $50 ', 0 = ' '
-
- - - If negative, space before number is '-', if positive then ' '.
- Can also follow the number.
-
- -####.## : 1234.56 = ' 1234.56', -5.00 = ' -5 ', 0 = ' '
-
- + - If negative, space before number is '-', if positive then '+'.
- Can also follow the number. The + will not be displayed if no
- digits in the number are displayed.
-
- +####.## : 1234.56 = '+1234.56', -5.00 = ' -5 ', 0 = ' '
-
- ( ) - If negative, parenthesis around number, else blanks around.
-
- (####.#) : 1234.5 = ' 1234.5 ', -5.00 = ' (5 )', 0 = ' '
-
-
- , - Thousands separator (comma).
- . - Decimal separator (period).
-
- #,###.## : 1234.56 = '1,234.56', 50.00 = ' 50 ', 0 = ' '
-
- SEE ALSO
- S2I - String to Integer
-
- DEPENDS ON
-
- DIAGNOSTICS
- The mask must have the proper characters present or the resulting
- string will be invalid. If the Mask is too small to hold the number
- all stars '*' will be returned. If the number is negative and a sign
- character has not been used then the result will also be all stars.
- If the mask is inconsistant, and cannot be decoded, then all questions
- '?' will be returned.
-
- KNOWN RESTRICTIONS
- THERE IS CURRENTLY NO CHECKING DONE OF THE MASK. This means that a
- mask of $#$#$# is perfectly valid and will return a dollar sign
- between every digit.
-
- Will float either the sign (-,+), or the dollar sign (+), but will only
- float both if the minus sign is used: (-$ or $-)
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:R2S - Real to String Conversion
- R2S - Real to String Conversion
- .K:D2S - Double to String Conversion
- D2S - Double to String Conversion
-
- SYNOPSIS
- FUNCTION R2S (Num : REAL; Mask : STRING) : STRING;
- FUNCTION D2S (Num : DOUBLE; Mask : STRING) : STRING;
-
- WRITELN ('Total Due: ', R2S (4356.50, '$(#####.##)');
- WRITELN ('Miles to Neptune: ', D2S (123456789.4356, '###,###,##,##@.##)');
-
- DESCRIPTION
- Returns a string of the real number passed. The number of decimal
- places is calculated from the mask. Therefore, the mask "##.###"
- specifies a field length of 6 and 3 decimal places. The decimal
- places are rounded, but a .5 is rounded DOWN. This is a function of
- the Turbo routine STR, and if you want to round up, you'll have to add
- some small fraction to your number. Also remember that if you specify
- more than 24 decimal positions the result will be in scientific
- notation which is curently not supported very well. See I2S for more
- info on the mask parameter, and the characters within the mask.
-
- SEE ALSO
- I2S - Integer to String, S2R - String to Real
-
- DEPENDS ON
-
- DIAGNOSTICS
- The mask must have the proper characters present or the resulting
- string will be invalid. If the Mask is too small to hold the number
- all stars '*' will be returned. If the number is negative and a sign
- character has not been used then the result will also be all stars. If
- the mask is inconsistant, and cannot be decoded, then all questions
- '?' will be returned.
-
- KNOWN RESTRICTIONS
- THERE IS CURRENTLY NO CHECKING DONE OF THE MASK. This means that a
- mask of $#$#$# is perfectly valid and will return a dollar sign
- between every digit.
-
- To print a phone number just make the 10 digit number negative and use
- the following mask '(###) ###-####'
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:S2R - String to Real Conversion
- S2R - String to Real Conversion
- .K:S2D - String to Double Conversion
- S2D - String to Double Conversion
-
- SYNOPSIS
- FUNCTION S2R (Source : STRING) : REAL;
- FUNCTION S2D (Source : STRING) : DOUBLE;
-
- VAR
- Number : REAL:
-
- BEGIN
- Number := S2R ('$( 1,435.43)');
- WRITELN(S2D('12345.6789');
- END;
-
- DESCRIPTION
- Converts a string into a real number. All characters that are not in
- the set ['0'..'9', '.'] are simply ignored. However, parenthesis and
- minus signs are scanned for (sic) to determine the sign of the number.
- All real numbers are assumed to be base 10.
-
- SEE ALSO
- R2S - Real to String
- StrNumTest
-
- DEPENDS ON
-
- DIAGNOSTICS
- If the string contains no valid digits then the value zero will be
- returned; test the string first with StrNumTest. If the string contains
- more digits than will fit into a real number then a run-time error will
- occur halting the program.
-
- If a conversion error can't be trapped before the string is actually
- converted with the Turbo VAL proc, the string and the character
- position of the failed conversion will be displayed, and zero will be
- returned.
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:StrNumTest - Test Numeric String.
- StrNumTest - Test Numeric String.
-
- SYNOPSIS
- FUNCTION StrNumTest (Fld : STRING) : StrNumType;
-
- VAR
- StrNumOrd : StrNumType
- StrNum : STRING;
-
- BEGIN
- StrNumOrd := StrNumTest(StrNum);
- CASE StrNumOrd OF
- StrNonNumeric : WRITELN('String has no numeric characters');
- StrZero : WRITELN('String has numeric value of zero');
- StrNonZero : WRITELN('String has numeric value of non zero');
- END;
- WRITELN(S2L(StrNum));
- END;
-
- DESCRIPTION
- Returns an ordinal value of NonNumeric, Zero, or NonZero for the string
- parameter supplied. If no numeric charcters 0..9 are found, then
- NonNumeric is returned. Otherwise If the string 'value' is zero, then
- Zero is returned. Otherwise NonZero is returned. Since S2x returns zero
- for nonnumerics and overflow, as well as legitimate zero, invoking this
- function first is advised.
-
- SEE ALSO
- S2I
-
- DEPENDS ON
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:S2I - String to Integer Conversion
- S2I - String to Integer Conversion
- .K:S2W - String to WordConversion
- S2W - String to Word Conversion
- .K:S2L - String to LongInt Conversion
- S2L - String to LongInt Conversion
-
- SYNOPSIS
- FUNCTION S2I (Source : STRING) : INTEGER;
- FUNCTION S2W (Source : STRING) : WORD;
- FUNCTION S2L (Source : STRING) : LONGINT;
-
- VAR
- HexNumber : INTEGER;
-
- BEGIN
- WRITELN(S2I('32,767'));
- HexNumber := S2W ('H4BAD');
- WRITELN(S2L('2,123,456,890'));
- END;
-
- DESCRIPTION
- Converts a string into an integer value. If the string has the letter
- H before or after the number, the number is assumed to be in
- hexidecimal format and is coverted as such. If the string has the
- letter B before or after the number it is assumed to be a binary
- number and converted as such. All characters which cannot be digits
- are removed from the string. For example, all commas are removed. In
- a binary number any character which is not a '0' or '1' is removed so
- that the number 1231 will have the binary string value '11' which
- equals 3. The conversion will also stop after the first '.' found, i.e
- '123.45' will convert to 123.
-
- SEE ALSO
- I2S - Integer to String
- StrNumTest
-
- DEPENDS ON
-
- DIAGNOSTICS
- If no numeric characters are found, or the numeric value overflows the
- result type, zero will be returned; test the string first with
- StrNumTest.
-
- If a conversion error can't be trapped before the string is actually
- converted with the Turbo VAL proc, the string and the character
- position of the failed conversion will be displayed, and zero will be
- returned.
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
-
- .K:2) DATE AND TIME FORMATTING AND CONVERSION
- 2) DATE AND TIME FORMATTING AND CONVERSION
-
- NAME
- .K:Numth - Returns a string with the number followed by 'th'
- Numth - Returns a string with the number followed by 'th'
-
- SYNOPSIS
- FUNCTION NumTh (Num : INTEGER) : MaxStr;
-
- WRITELN ('Today is the ', Numth (5), ' day of the week.');
-
- DESCRIPTION
- Converts a decimal integer into a string with a following 'th' as in
- 4th, 3rd, 2nd and 1st. This routine is really for use with the date
- conversions, but it might be useful elsewhere.
-
- SEE ALSO
- Date2S - Date to String
-
- DEPENDS ON
- I2S
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:Date2R - Date to Real.
- Date2R - Date to Real.
-
- SYNOPSIS
- PROCEDURE Date2R (VAR JulSec : REAL; DateTime : T_DateTime);
-
- VAR
- NumberSeconds : REAL;
-
- BEGIN
- WITH DateTime DO BEGIN
- Month := 6;
- Day := 13;
- Year := 1986;
- Hour := 00;
- Minute := 23;
- Second := 44;
- END;
-
- Date2R (NumberSeconds, DateTime);
- WRITELN ('Seconds from 12/31/1840 midnight: ', NumberSeconds);
- END;
-
- DESCRIPTION
- Date to Real returns a real number which is the number of "Julian
- seconds" from some known point. The variable DateTime contains the
- exact time in month day year hours minutes and seconds. All these are
- multiplied (taking into account leap years properly) to arrive at the
- number of seconds.
-
- SEE ALSO
- R2Date - Real to Date, Date2S - Date to String, GetDOSDateAndTime
-
- DEPENDS ON
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
- No testing is done for negative values.
- Leap years AND Leap centuries ARE correctly handled.
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:R2Date - Real to DateTime
- R2Date - Real to DateTime
-
- SYNOPSIS
- PROCEDURE R2Date (JulSec : REAL; VAR DateTime : T_DateTime);
-
- VAR
- DT : T_DateTime;
-
- BEGIN
- R2Date (8904534450.0, DT);
- WRITELN ('Today is: ', Date2S (DT, 'WWWW'));
- END;
-
- DESCRIPTION
- Converts the number of julian seconds to the DateTime record while
- properly converting leap years and leap centuries.
-
- SEE ALSO
- Date2S - Date to String, Date2R - Date to Real
-
- DEPENDS ON
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:Date2S - Date to String.
- Date2S - Date to String.
-
- SYNOPSIS
- FUNCTION Date2S (DateTime : T_DateTime; Mask : MaxStr) : MaxStr;
-
- WRITELN ('Today is: ', Date2S(DateTime, 'WWW MM/DD/YY hh:mm:ss pm'));
-
- DESCRIPTION
- Date to string returns a string with the correctly formatted date and
- time. The mask can consist of any of the following characters:
-
- (The case of the below is significant! e.g. 'W' <> 'w')
-
- WWW - Three letter weekday name
- WWWW - Full weekday name, variable length
- MM - Numeric month
- MMM - Three letter month name
- MMMM - Full month name, variable length
- DD - Numeric day of month, with leading zeros
- DDDD - Day of month, leading spaces, followed by st, nd, rd or th
- YY - Year in century, 20 could mean 1820, 1920, 2020, etc
- YYYY - Full year
- hh - Hours either in 24 or 12 format
- mm - Minutes
- ss - Seconds
- a - Am indicator - changes to 12 hour format am and pm shown
- p - Am indicator - changes to 12 hour format only pm is shown
- E - European date expected, e.g. EYY/MM/DD
-
- SEE ALSO
- Date2R - Date to Real, R2Date - Real to Date, GetDOSDateAndTime
-
- DEPENDS ON
-
- DIAGNOSTICS
- If the mask passed is incorrect, parts of the mask will simply be
- returned unfilled. If any the integer fields in the DateTime record
- are larger than 99 or less than 0 the mask may have stars in those
- fields indicating overflow.
-
- KNOWN RESTRICTIONS
- No parsing is performed on the mask. The mask will not be filled
- properly unless the mask characters are in the correct order.
- Weekdays, Month, Day, Year followed by hour minute and second. Any of
- them may be left out, but if they are out of order, it won't work.
-
- PARTIALLY OBSOLETED BY
- UnPackTime
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:GetDOSDateAndTime - Returns both the number of seconds from 12/31/1840
- GetDOSDateAndTime - Returns both the number of seconds from 12/31/1840
- midnight, and the DateTime record containing the
- date, time and elapsed times from the DOS system
- clock.
-
- SYNOPSIS
- PROCEDURE GetDOSDateAndTime (VAR JulSec : REAL;
- VAR DateTime : T_DateTime);
-
- VAR
- Seconds : REAL;
- DOSDateTime : T_DateTime;
-
- BEGIN
- GetDOSDateAndTime (Seconds, DOSDateTime);
- WRITELN ('Today is: ', D2S (DOSDateTime, 'MM/DD/YY');
- END;
-
- DESCRIPTION
- Both the number of seconds from 1840 and the DateTime record are
- returned by this routine. The DOS values are retrieved using DOS
- calls. This routine also calls both Date2R and R2Date to update the
- variables in DateTime (the elapsed time vars).
-
- SEE ALSO
- Date2R - Date to Real, R2Date - Real to Date, Date2S - Date to String
-
- DEPENDS ON
- Date2R
- R2Date
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
- GetDate, GetTime
-
- UPDATE HISTORY
-
-
-
- NAME
- .K:SetDOSDateAndTime - Sets both the DOS date and time
- SetDOSDateAndTime - Sets both the DOS date and time.
-
- SYNOPSIS
- PROCEDURE SetDOSDateAndTime (DateTime : T_DateTime);
-
- VAR
- JS : REAL;
- DT : T_DateTime;
-
- BEGIN
- GetDOSDateAndTime (JS, DT);
- DT.Month := 3;
- DT.Day := 5;
- DT.Year := 1986;
- SetDOSDateAndTime (DT);
- END;
-
- DESCRIPTION
- Both the date and time will be reset at the DOS level. If you only
- want to reset the date, you should call GetDOSDateAndTime first,
- otherwise, the time that is set will be random. Of course, you can
- set both date and time to the correct values, or you could set the
- time to zero.
-
- SEE ALSO
- Date2R, R2Date, Date2S, GetDOSDateAndTime
-
- DEPENDS ON
-
- DIAGNOSTICS
-
- KNOWN RESTRICTIONS
-
- PARTIALLY OBSOLETED BY
- SetDate, SetTime
-
- UPDATE HISTORY
-
-
-
-